package cn.dfun.demo.scdemo.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;


    public CommonResult(Integer code, String msg) {
        this(code, msg, null);
    }

    public CommonResult(ResultEnum resultEnum, T data) {
        this(resultEnum.getCode(), resultEnum.getMsg(), data);
    }

    public static CommonResult success() {
        return new CommonResult(ResultEnum.SUCCESS, null);
    }

    public static<T> CommonResult success(T data) {
        return new CommonResult(ResultEnum.SUCCESS, data);
    }

    public static<T> CommonResult success(String msg, T data) {
        return new CommonResult(ResultEnum.SUCCESS.getCode(), msg, data);
    }

    public static CommonResult fail() {
        return new CommonResult(ResultEnum.FAIL, null);
    }

    public static CommonResult fail(String msg) {
        return new CommonResult(ResultEnum.FAIL.getCode(), msg, null);
    }
}
